package org.lsms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lsms.bean.Paper_Grade;
import org.lsms.dao.impl.DaoImpl;

public class paper_grade extends HttpServlet {

	public void destroy() {
		super.destroy(); 
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			int reviewer_id = Integer.parseInt(request.getParameter("reviewer_id"));
			int paper_id = Integer.parseInt(request.getParameter("paper_id"));
			
			int problem_a = Integer.parseInt(request.getParameter("A"));
			int problem_b = Integer.parseInt(request.getParameter("B"));
			int problem_c = Integer.parseInt(request.getParameter("C"));
			int problem_d = Integer.parseInt(request.getParameter("D"));
			int problem_e = Integer.parseInt(request.getParameter("E"));
			
			String note_to_member = request.getParameter("note_to_member");
			
			int recommend = Integer.parseInt(request.getParameter("recommend"));
			
			String note_to_author = request.getParameter("note_to_author");
			String expertise = request.getParameter("expertise");
			
			Paper_Grade paper_grade = new Paper_Grade();
			
			paper_grade.setExpertise(expertise);
			paper_grade.setNote_to_author(note_to_author);
			paper_grade.setNote_to_member(note_to_member);
			paper_grade.setProblem_a(problem_a);
			paper_grade.setProblem_b(problem_b);
			paper_grade.setProblem_c(problem_c);
			paper_grade.setProblem_d(problem_d);
			paper_grade.setProblem_e(problem_e);
			paper_grade.setRecommend(recommend);
			
			DaoImpl impl = new DaoImpl(); 
			
			if(impl.paper_grade(paper_grade, reviewer_id, paper_id) && impl.update_paper_assign2_status(1, paper_id, reviewer_id)){
				String reviewer_info = "Submit Succeed!";
				response.sendRedirect("reviewer/reviewer_show_info.jsp?reviewer_info="+reviewer_info);
			}else{
				String reviewer_info = "Submit Failed!Please try again later.";
				response.sendRedirect("reviewer/reviewer_show_info.jsp?reviewer_info="+reviewer_info);
			}
			
	}

	public void init() throws ServletException {

	}

}
